package sd.qd.xiaoming.coffeedesk.dao;

import java.util.List;

import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;

import sd.qd.xiaoming.coffeedesk.entity.CdDirectory;

@Repository
public class CdDirectoryDAO extends BaseDAO<CdDirectory> {

    public CdDirectoryDAO() {
        super(CdDirectory.class);
    }

    public List<CdDirectory> findByParent(final CdDirectory parent) {

        if (null == parent) {
            return this.entityManager.createQuery(
                    "select d from CdDirectory d where d.parent is null",
                    CdDirectory.class).getResultList();
        }

        TypedQuery<CdDirectory> query = this.entityManager.createQuery(
                "select d from CdDirectory d where d.parent=:parent",
                CdDirectory.class);
        query.setParameter("parent", parent);
        return query.getResultList();
    }

}
